<?php

// 广告位表

namespace app\console\model;
use think\Db;
use think\Model;
use think\Request;
use app\common\trilateral\Classify as ClassifyAlias;
use think\Session;
use think\Hook;

class DrawTime extends Model
{
    // 模型事件
    protected static function init()
    {

        self::event('before_write', function ($data) {
            $data->pic_url = uploadImg('pic_url');
            $apply_time = explode('/',Request::instance()->param()['apply_time']);
            $data->apply_start_time = $apply_time[0];
            $data->apply_end_time = $apply_time[1];
            auding($data);
        });



        self::event('after_write', function ($data) {
            $param = Request::instance()->param();
            //Db::name('draw_time_gift')->where('draw_id',$data->id)->delete();
            $shop_assignor_records = [];
            if(!empty($param['draw_title'])){
                for ($i = 0; $i < count($param['draw_title']); $i++) {
                    $shop_assignor_records[$i]['draw_id'] = $data->id;
                    $shop_assignor_records[$i]['draw_title'] = $param['draw_title'][$i];
                    $shop_assignor_records[$i]['draw_probability'] = $param['draw_probability'][$i];
                    $shop_assignor_records[$i]['create_time'] = date('Y-m-d H:i:s',time());
                    Db::name('draw_time_gift')->insert($shop_assignor_records[$i]);
                }
            }

        });
    }

    public function getAudingTextAttr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status']];
    }

    public function getAudingText1Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status1']];
    }
    public function getAudingText2Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status2']];
    }
    public function getAudingText3Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status3']];
    }



}